<a href="#" class="selected-language"><img src="<?php echo $this->getFlagImageUrl($selectedLocaleId); ?>" /></a>
<?php if (count($localeIds) > 0) : ?>
    <ul>
    <?php
    $domain = parse_url(Yii::app()->request->getHostInfo(), PHP_URL_HOST);
    $num = 0;
    foreach($localeIds as $localeId) :
        if ($localeId == $selectedLocaleId) continue;
        $workFlow = Workflow::model()->find("locale_id=:localeId AND type=:type AND url LIKE '%".$domain."%'",array(':localeId'=>$localeId,':type'=>Workflow::TYPE_FINAL));
        if (is_null($workFlow)) continue; $num++;
    ?> 
        <li<?php if ($num==1) echo ' class="first"' ?>><a href="<?php echo 'http://'.$workFlow->url.'/index.html'; ?>"><img src="<?php echo $this->getFlagImageUrl($localeId); ?>" /></a></li>
    <?php endforeach; ?>
    </ul>
<?php endif; ?>
